#include "capturethread.h"

#include <QDebug>
#include <QGuiApplication>
#include <QScreen>
#include <QPixmap>
#include <QBuffer>
#include <QSettings>
#include "myconfig.h"

CaptureThread::CaptureThread(TcpSession *session, QObject *parent):QThread(parent),session(session)
{
    int number=MyConfig::getValue("video/frame.per.second").toInt();
    interval_us=1*1000*1000/number;
}

CaptureThread::~CaptureThread()
{

}

void CaptureThread::init()
{

}

void CaptureThread::run()
{
    QScreen* screen=QGuiApplication::primaryScreen();
    QString mode=MyConfig::getValue("video/pix.mode");
    while(1){
        //为了方便测试，
        QPixmap pix;
        if(mode == "2"){
            pix=screen->grabWindow(0,0,screen->size().width()/2,screen->size().height()/2);
        }else{
            pix = screen->grabWindow(0);
        }

        emit pixCaptured(pix);

        QThread::usleep(interval_us);
    }
}
